package com.briup.jz.web.controller;

import com.briup.jz.bean.Order;
import com.briup.jz.service.IOrderService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("order")
@Api(description="订单管理")
public class OrderController {

    @Autowired
    private IOrderService iOrderService ;
    @ApiOperation("提交订单")
    @PostMapping("submitOrder")
    public Message saveorupdate(Order order){
        iOrderService.saveOrUpdate(order);
        return MessageUtil.success("操作成功");
    }
    @GetMapping("findbyid")
    @ApiOperation("查询订单详情")
  @ApiImplicitParam(name = "id",value = "订单号",paramType = "query")
    public  Message query(Long id){
        List<Order> orders = iOrderService.query(id);
        return MessageUtil.success(orders);
    }
    @ApiOperation("通过id删除")
    @GetMapping("deleteById")
    @ApiImplicitParam(name = "id",value = "订单号",paramType = "query",required=true)
    public  Message delete(Long id){
        iOrderService.deleteById(id);
        return MessageUtil.success("操作成功");
    }
    @ApiOperation("取消派单")
    @GetMapping("cancelSendOrder")
    @ApiImplicitParam(name = "id",value = "订单号",paramType = "query",required=true)
    public Message cancelSendOrder(Long id ) {
    	iOrderService.cancelSendOrder(id);
    	return MessageUtil.success("操作成功");
    }
    @ApiOperation("确认接单")
    @GetMapping("confirmOrder")
    @ApiImplicitParam(name = "id",value = "订单号",paramType = "query",required=true)
    public Message confirmOrder(Long id ) {
    	iOrderService.confirmOrder(id);;
    	return MessageUtil.success("操作成功");
    }
    @ApiOperation("拒绝接单")
    @GetMapping("rejectOrder")
    @ApiImplicitParam(name = "id",value = "订单号",paramType = "query",required=true)
    public Message rejectOrder(Long id ) {
    	iOrderService.rejectOrder(id);;
    	return MessageUtil.success("操作成功");
    }
    @ApiOperation("员工服务结束")
    @GetMapping("competeorder")
    @ApiImplicitParam(name = "id",value = "订单号",paramType = "query",required=true)
    public Message competeorder(Long id ) {
    	iOrderService.competeorder(id);;
    	return MessageUtil.success("操作成功");
    }
    @ApiOperation("派单")
    @GetMapping("sendorder")
    @ApiImplicitParam(name = "id",value = "订单号",paramType = "query",required=true)
    public Message sendorder(Long id ) {
    	iOrderService.sendOrder(id);;
    	return MessageUtil.success("操作成功");
    }
    @ApiOperation("接单")
    @GetMapping("takeorder")
    @ApiImplicitParam(name = "id",value = "订单号",paramType = "query",required=true)
    public Message takeorder(Long id ) {
    	iOrderService.takeOrder(id);;
    	return MessageUtil.success("操作成功");
    }
}
